package com.android.xk.mask.guard

import android.app.Service
import android.app.smdt.SmdtManager
import android.content.Intent
import android.os.IBinder
import com.android.xk.mask.IGuardInterface
import com.apkfuns.logutils.LogUtils

class RemoteService : Service()
{

    private var remoteServiceBinder: RemoteServiceBinder? = null

    override fun onBind(intent: Intent): IBinder
    {
        remoteServiceBinder = RemoteServiceBinder()
        return remoteServiceBinder as RemoteServiceBinder
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int
    {
        LogUtils.i("开始远程服务")
        return super.onStartCommand(intent, flags, startId)
    }

    inner class RemoteServiceBinder : IGuardInterface.Stub()
    {
        override fun basicTypes(
                anInt: Int,
                aLong: Long,
                aBoolean: Boolean,
                aFloat: Float,
                aDouble: Double,
                aString: String?
        )
        {
        }

        override fun getServiceName(): String
        {
            return RemoteService::class.java.name
        }

        override fun appUpdate(filePath: String?, operateType: Int)
        {
            LogUtils.e("更新应用")
            SmdtManager.create(applicationContext)
                    .smdtSilentInstall("/sdcard/Download/app.apk", applicationContext)
            LogUtils.e("更新完成")
        }
    }
}
